import { useUserinfoApi, useNavMenuApi } from "@/api/index";
import Toast from "@vant/weapp/toast/toast";
const app = getApp();
Page({
  data: {
    darpdownTop: 0,
    searchHeight: 47,
    contentSafeHeight: app.globalData.contentSafeHeight,
    tenantList: [],
    authBtnList: [],
    tenantName: "",
    swiperList: [
      {
        url: "/resource/home/sw/Vector.png",
      },
      {
        url: "/resource/home/sw/banner3.jpg",
      },
    ],
  },
  onShow() {
    if (typeof this.getTabBar === "function" && this.getTabBar()) {
      this.getTabBar().setData({
        selected: 0,
      });
    }
  },
  onLoad(options) {
    let tenantName = options.name || wx.getStorageSync("tenantName");
    let tenantId = options.id;
    this.setData({
      tenantName,
    });
    // if (!this.data.tenantName) {
    //   this.setData({
    //     tenantName: wx.getStorageSync("tenantName"),
    //   });
    // }
    this.getUserinfo();
    // 屏幕顶部状态栏高度
    let menu = wx.getMenuButtonBoundingClientRect();
    // 胶囊区距离屏幕顶部的距离
    let menuTop = menu.top;
    this.setData({
      darpdownTop: menuTop + 3,
    });
  },
  //获取用户信息
  async getUserinfo() {
    let {
      data: { tenantList, authBtnList },
    } = await useUserinfoApi();
    this.setData({
      tenantList,
      authBtnList,
    });
    //存储按钮权限
    app.globalData.authBtnList = authBtnList;
  },
  inPage(e) {
    let { authBtnList } = this.data;
    let { name, pageurl } = e.target.dataset;
    console.log(name, pageurl);
    console.log(pageurl);
    if (authBtnList.includes(name)) {
      wx.navigateTo({
        url: pageurl,
      });
    } else {
      Toast.fail("暂无权限访问");
    }
  },
});
